//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core;
using OpenLS.Spreadsheet.Internals;

namespace OpenLS.Spreadsheet
{
    class ColumnWidthUndoUnit: CompositeUndoUnit
    {
        public ColumnWidthUndoUnit(Column column): base (StringTable.ColumnWidth)
        {
            this.column = column;
            value = column.CharacterWidth;
        }

        readonly Column column;
        readonly double? value;

        #region IUndoUnit Members

        internal override ICompositeUndoUnit GetEmptyClone()
        {
            return new ColumnWidthUndoUnit(column);
        }
        protected override void DoSelf()
        {
            column.CharacterWidth = value;
        }

        public override bool Merge(IUndoUnit unit)
        {
            if (unit is ColumnWidthUndoUnit)
            {
                ColumnWidthUndoUnit cu = (ColumnWidthUndoUnit)unit;
                return cu.column == column;
            }
            return false;
        }


        #endregion

    }
}
